package Controller.GestionGroupe;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Controller.BDD.GestionGroupeBDD;
import Model.Groupe;

/**
 * Servlet implementation class CreerGroupe
 */
@WebServlet("/CreerGroupe")
public class CreerGroupe extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CreerGroupe() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String urlVue = "/GestionGroupes";
		String message = "";
		
		String nom 		   = (String) request.getParameter("nom");
		String description = (String) request.getParameter("description");
		
		Groupe newGroupe = new Groupe(1,nom, description, null,null);
		
		System.out.println(nom);
		System.out.println(description);
		try {
			GestionGroupeBDD.insererGroupe(newGroupe);
		} catch (Exception e) {
			message = e.getMessage();
		}
		
		//request.setAttribute("msg", message);
		//request.getRequestDispatcher(urlVue).forward(request, response);
		response.sendRedirect("GestionGroupes");	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
